Skip to content

[MySQL] az mysql flexible-server db create: Fix --charset and --collation being ignored - #34412

Open
nabeleon94 wants to merge 1 commit into
Azure:devfrom
nabeleon94:fix/mysql-db-create-charset
Open

nabeleon94 wants to merge 1 commit into
Azure:devfrom
nabeleon94:fix/mysql-db-create-charset

Conversation

@nabeleon94

@nabeleon94 nabeleon94 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ️✔️ None

Related command
az mysql flexible-server db create, and the default database created by az mysql flexible-server create

Description
Fixes #34410.

database_create_func and _create_database passed begin_create_or_update a plain dict with charset and collation at the top level (plus name). azure-mgmt-mysqlflexibleservers 1.1.0b3 serializes a plain dict as-is, and on the Database model charset/collation are flattened properties that have to go under properties. So the service ignored them, and the database got the server defaults (e.g. utf8mb4 / utf8mb4_0900_ai_ci on MySQL 8.4) while the command exited 0. That includes the utf8 / utf8_general_ci defaults the command applies when neither argument is given.

Both places now build models.Database(charset=..., collation=...), the same way firewall_rule_create_func builds models.FirewallRule, so the body becomes {"properties": {"charset": ..., "collation": ...}}. The read-only name is no longer sent; the database name is still in the URL.

Testing Guide
New unit tests in test_mysql_custom.py (MysqlFlexibleServerDatabaseCustomTest). A fake databases client serializes parameters with the SDK's own SdkJSONEncoder, the same call the SDK uses to build the request body:

  • db create with --charset utf8mb3 --collation utf8mb3_unicode_ci
  • db create with neither argument (defaults)
  • _create_database (server create's default database)

All three fail before the fix (body is {"name": ..., "charset": ..., "collation": ...}) and pass after.

python -m pytest src/azure-cli/azure/cli/command_modules/mysql/tests/latest/test_mysql_custom.py -q
# 9 passed
python -m pytest src/azure-cli/azure/cli/command_modules/mysql/tests/latest/test_mysql_scenario.py -k "proxy_resource or byok_mgmt" -q
# 2 passed (playback; both run `db create`)

flake8 is clean on the changed lines. Not run live against a server.

History Notes
[MySQL] az mysql flexible-server db create: Fix --charset and --collation being ignored


This checklist is used to make sure that common guidelines for a pull request are followed.

Copilot AI balanced review requested due to automatic review settings November 12, 2026 17:01
@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Nov 12, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution nabeleon94! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the MySQL database creation payload change.

No open issues 🎉

What changed in this PR

Fixes #34410 by ensuring MySQL flexible-server database creation sends charset and collation under properties, so Azure receives the requested values rather than silently using server defaults.

Changes:

  • Uses SDK Database models for both db create and the default database created during server provisioning.
  • Removes the read-only database name from the request body while preserving it in the URL.
  • Adds serialization regression tests for explicit values, command defaults, and server-created databases.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​mysql/​tests/​latest/​test_mysql_custom.py Adds three regression tests using the SDK JSON encoder to verify request payloads.
src/​azure-cli/​azure/​cli/​command_modules/​mysql/​custom.py Replaces plain dictionaries with Database models in both database creation paths.

Review effort: Balanced

@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az mysql flexible-server db create ignores --charset and --collation

4 participants